package com.soso.j.spider.queue.api.impl;

import java.io.IOException;
import java.util.Map;

import com.soso.core.queue.Task;
import com.soso.core.util.html.HttpRequester;
import com.soso.core.util.log.Logger;
import com.soso.j.spider.config.SystemProperty;

public class TaskExecutor extends Thread{
	
	private Task task;
	public TaskExecutor(final Task task){
		this.task=task;
	}
	@Override
    public void run() {
		String urlString=SystemProperty.getServerPath();
		
		if(task.getUrl().startsWith("/")
				&& urlString.endsWith("/")){
			urlString+=task.getUrl().substring(1);
		}else{
			urlString+=task.getUrl();
		}
		Integer dataLen=null;
		String receiveEncoding=null;
		String defaultContentEncoding=null;
		Map<String,String> params=task.getParams();
		Map<String,String> propertys=task.getHeaders();
		try {
			if("POST".equals(task.getMethod().name())){
				HttpRequester.sendPost(urlString, dataLen, receiveEncoding, defaultContentEncoding, params, propertys);
			}else{
				HttpRequester.sendGet(urlString, dataLen, receiveEncoding, defaultContentEncoding, params, propertys);
			}
		} catch (IOException e) {
			Logger.error(e.getMessage());
		}	
    }
	
}
